package auth

import (
	"gin-demo/sysinit"
	"log"

	"github.com/gin-gonic/gin"
)

// InitUserRouters 初始化账户相关路由
func InitUserRouters(router *gin.Engine, urlPrefix string) {
	c := UserController{}
	authRouters := router.Group(urlPrefix)
	{
		authRouters.POST("/login", JWT.LoginHandler)
		authRouters.POST("/refesh_token", JWT.RefreshHandler)
		authRouters.POST("/register", c.Register)
		authRouters.PATCH("/change_password/:id", c.ChangePassword)
		authRouters.GET("/users", JWT.MiddlewareFunc(), c.List)
	}
}

func init() {
	log.Println("init module auth")
	sysinit.DB.AutoMigrate(
		&User{},
	)
	InitJWT()
	InitUserRouters(sysinit.Router, "/auth")
}
